package com.hspedu.newData.dmsxl.数组.模拟;
/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-10 
 * @Version: 1.0
 */

public class LC867转置矩阵 {

    public int[][] transpose(int[][] matrix) {

        int m = matrix.length;
        int n = matrix[0].length;
        if (m==n){
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < i; j++) {
                    int temp = matrix[i][j];
                    matrix[i][j] = matrix[j][i];
                    matrix[j][i] = temp;
                }
            }
            return matrix;
        }else{
            int[][] res = new int[n][m];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    res[j][i] = matrix[i][j];
                }
            }
            return res;
        }
    }
}
